<?php

declare (strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
class EnterpriseCertification extends Model
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected ?string $table = 'enterprise_certification';
    public static $statusList = [1 => '待审核', 2 => '审核通过', 3 => '审核未通过'];
    public function img()
    {
        return $this->belongsTo(Upload::class, 'img_id');
    }
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    public function auditor()
    {
        return $this->belongsTo(Manager::class, 'auditor_id');
    }
    /**
     * 审核
     * @param $status
     * @return $this
     */
    public function audit($status)
    {
        $this->status = $status;
        return $this;
    }
    public function getStatusTextAttribute()
    {
        return static::$statusList[$this->status] ?? '待审核';
    }
    /**
     * 接口返回
     * @return array
     */
    public function toApi()
    {
        return ['id' => $this->id, 'name' => $this->name ?? '', 'code' => $this->code ?? '', 'address' => $this->address ?? '', 'mobile' => $this->mobile ?? '', 'img_id' => $this->img_id ?? '', 'img' => stripslashes(($this->img->url ?? '')), 'status' => $this->status ?? 1, 'status_text' => $this->status_text];
    }
}